import { createRouter, createWebHistory } from 'vue-router'
import {ElMessage, ElNotification} from "element-plus";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
     redirect:"index",
      children: [
        {
          path: '/index',
          name:"index",
          component: () => import('../views/IndexView.vue')
        },
        {
          path: '/course',
          name: '课程',
          component: () => import('../views/course/CourseView.vue'),
        }
      ]
    },
    {
      path: '/login',
      name: '登录',
      component: () => import('../views/LoginView.vue'),
    },
    {
      path: '/loginOfPhone',
      name:'手机号登录',
      component: () => import('../views/LoginOfPhone.vue'),
    },
    {
      path:'/wxlogin',
      name:'微信登陆',
      component: () => import('../views/WxLogin.vue'),
    },
    {
      path:'/wxBind',
      name:'微信绑定',
      component: () => import('../views/WxBind.vue'),
    },
    {
      path:'/bindWeChat/:studentId',
      name:'绑定微信',
      component:()=>import("@/views/personal/BindWeChat.vue")
    },
    {
      path: '/phoneBind',
      name: '用户绑定手机',
      component: () => import('@/views/PhoneBind.vue')
    },
    {
      path: '/homework',
      name: '课后作业',
      component: () => import('@/views/course/CourseHomeWork.vue'),
    },
    {
      path: '/personal',
      name: '个人中心',
      component: () => import('@/views/personal/IndexView.vue'),
      children: [
        {
          path: 'info',
          name: '个人信息',
          component: () => import('@/views/personal/InfoView.vue')
        },
        {
          path: 'leave',
          name: '我的请假',
          component: () => import('@/views/personal/LeaveView.vue')
        },
        {
          path: 'errorQuestion',
          name: '错题本',
          component: () => import('@/views/personal/ErrorQuestion.vue')
        },
        {
          path: 'employmentInfo',
          name: '我的就业',
          component: () => import('@/views/personal/EmploymentInfo.vue')
        },
        {
          path: 'questionsComments',
          name: '我的评论',
          component: () => import('@/views/personal/QuestionsComments.vue')
        }
      ]
    },
    {
      path: '/exam',
      name: '考试',
      component: () => import('../views/exam/ExamView.vue'),
    },
    {
      path: '/createExam',
      name: '开始考试',
      component: () => import('../views/exam/CreateExam.vue'),
    },
    {
      path: '/questionBank',
      name: '题库',
      component: () => import('../views/question/questionBank/QuestionBankView.vue'),
    },
    {
      path: '/startQuestion',
      name: '开始刷题',
      component: () => import('../views/question/questionBank/StartQuestionView.vue'),
    },
    {
      path: '/questionComment',
      name: '评论区',
      component: () => import('../views/question/questionBank/QuestionCommentView.vue'),
    }
  ]
})
//路由守卫
router.beforeEach((to, from, next) => {
  if (localStorage.getItem("frontToken") == null &&to.path !== '/phoneBind' && to.path !== '/login' && to.path !== '/loginOfPhone' && to.path !=='/wxlogin' &&to.path !== '/wxBind' ) {
    ElMessage.error('请先登录');
    router.push("/login")
  } else {
    next()
    }
});
export default router
